package com.zhiyou100.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.model.HospitalClear;
import com.zhiyou100.service.AccountService;

@Controller
public class AccountController {
	@Autowired
	private AccountService accountService;
	@RequestMapping("/account/list")
	public String AccountList(@RequestParam(defaultValue="")String patient,
			@RequestParam(defaultValue="")String medicalRecord,
			@RequestParam(defaultValue="1")int pageNo,Model model) {
		Map<String,Object> map = new HashMap<>();
		map.put("medicalRecord", medicalRecord);
		map.put("patient", patient);
		PageHelper.startPage(pageNo, 2);
		List<HospitalClear> lists = accountService.findAll(map);
		PageInfo<HospitalClear> pageInfo = new PageInfo<>(lists);
		model.addAttribute("map", map);
		model.addAttribute("page", pageInfo);
		model.addAttribute("lists", pageInfo.getList());
		return "forward:/view/hospital/AccountList.jsp";
	}
	@RequestMapping("/account/update")
	public String AccountUpdate(int id) {
		System.out.println("==========");
		System.out.println("medical_record: ");
		accountService.updateById(id);
		return "forward:/account/list";
	}
	@RequestMapping("/account/detail")
	public String accountDetail(int id,Model model,@RequestParam(defaultValue="1")int pageNo) {
		PageHelper.startPage(pageNo, 1);
		List<HospitalClear> hc = accountService.findById(id);
		PageInfo<HospitalClear> pageInfo = new PageInfo<>(hc);
		model.addAttribute("hc", pageInfo.getList());
		model.addAttribute("page", pageInfo);
		model.addAttribute("id", id);
		return "forward:/view/hospital/accountDetail.jsp";
	}
}
